/**
 * http://brucexx.iteye.com/
 */
package com.brucexx.wedding.dao;

import java.util.List;

import javax.servlet.http.HttpSession;

import com.brucexx.wedding.model.Admin;
import com.brucexx.wedding.util.StringHelper;

/**
 * @author BruceXX email:brucest0078@gmail.com
 * 
 */
public class PermissionDAO {

	public static boolean isAdmin(String name) {
		List<Admin> list = BaseModelDAO.loadAll(Admin.class);
		for (Admin admin : list) {
			if (admin.getUsername().equals(name)) {
				return true;
			}
		}
		return false;
	}

	public static boolean isAdmin(HttpSession session) {
		String username = null;
		if (!StringHelper.isEmpty(username = StringHelper.null2String(session
				.getAttribute("username")))) {
			return isAdmin(username);
		}
		return false;
	}

	public static String getRealNameBySession(HttpSession session) {
		String username = null;
		if (!StringHelper.isEmpty(username = StringHelper.null2String(session
				.getAttribute("username")))) {
			List<Admin> list = BaseModelDAO.loadAll(Admin.class);
			for (Admin admin : list) {
				if (admin.getUsername().equals(username)) {
					return admin.getRealname();
				}
			}
		}
		return "匿名小黑";
	}
}
